package com.example.myanimator.mcanvas;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.example.myanimator.R;

/**
 * @author tgw
 * @date 2021/4/1
 * @describe  将Bitmap作为一个图层保存
 */
public class BitmapCanvasView extends View {
    private Paint mPaint;
    private Bitmap mBmp;
    private Canvas mBmpCanvas;

    public BitmapCanvasView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mPaint.setTextSize(30);
        mBmp = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
        mBmpCanvas = new Canvas(mBmp);


    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawLine(0, 100, getWidth(), 100, mPaint);
        mBmpCanvas.drawText("Canvas图层,不画bitmap的话文本 不会显示 因为它在一个新的canvas图层上面出现", 0, 100, mPaint);
        canvas.drawBitmap(mBmp,0, 0,mPaint);
    }
}